﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Agresso.Interface.Layer.Domain
{
    public class Vessel
    {
        public long vessel_id;
        public string vessel_name = string.Empty;
        public string vessel_code = string.Empty;
        public string year_of_build = string.Empty;
        public string flag = string.Empty;
        public string dwt = string.Empty;
        public string charter_type = string.Empty;
        public string size_class = string.Empty;
        public string vessel_type = string.Empty;
        public string vessel_sid = string.Empty;
        public string lloyd_number = string.Empty;

        public string agr_description = string.Empty;
        public string agr_dim_value = string.Empty;
        public string agr_rel_value = string.Empty;
        public string client = string.Empty;

        public ProfitCentre ProfitCentre;

        public DateTime created_date = new DateTime(1900, 1, 1);
        public DateTime modified_date = new DateTime(1900, 1, 1);

        public Vessel() { }
        public Vessel(bool isFromSoftmar, SqlDataReader rd)
        {
            if (!isFromSoftmar)
            {
                vessel_id = Convert.ToInt32(rd["vessel_id"]);
                agr_description = rd["agr_description"] is DBNull ? agr_description : rd["agr_description"].ToString();
                agr_dim_value = rd["agr_dim_value"] is DBNull ? agr_dim_value : rd["agr_dim_value"].ToString();
                agr_rel_value = rd["agr_rel_value"] is DBNull ? agr_rel_value : rd["agr_rel_value"].ToString();
                client = rd["client"] is DBNull ? client : rd["client"].ToString();
                created_date = rd["created_date"] is DBNull ? created_date : Convert.ToDateTime(rd["created_date"]);
                modified_date = rd["modified_date"] is DBNull ? modified_date : Convert.ToDateTime(rd["modified_date"]);
                ProfitCentre = new ProfitCentre(rd["profit_centre_id"] is DBNull ? 0 : Convert.ToInt32(rd["profit_centre_id"]));
            }
            vessel_name = rd["vessel_name"] is DBNull ? vessel_name : rd["vessel_name"].ToString();
            vessel_code = rd["vessel_code"] is DBNull ? vessel_code : rd["vessel_code"].ToString();
            year_of_build = rd["year_of_build"] is DBNull ? year_of_build : rd["year_of_build"].ToString();
            flag = rd["flag"] is DBNull ? flag : rd["flag"].ToString();
            dwt = rd["dwt"] is DBNull ? dwt : rd["dwt"].ToString();
            charter_type = rd["charter_type"] is DBNull ? charter_type : rd["charter_type"].ToString();
            size_class = rd["size_class"] is DBNull ? size_class : rd["size_class"].ToString();
            vessel_type = rd["vessel_type"] is DBNull ? vessel_type : rd["vessel_type"].ToString();
            vessel_sid = rd["vessel_sid"] is DBNull ? vessel_sid : rd["vessel_sid"].ToString();
            lloyd_number = rd["lloyd_number"] is DBNull ? lloyd_number : rd["lloyd_number"].ToString();
        }
        //public Vessel (bool softmar, SqlDataReader rd)
        //{
        //    vessel_name = rd["vessel_name"] is DBNull ? vessel_name : rd["vessel_name"].ToString();
        //    vessel_code = rd["vessel_code"] is DBNull ? vessel_code : rd["vessel_code"].ToString();
        //    year_of_build = rd["year_of_build"] is DBNull ? year_of_build : rd["year_of_build"].ToString();
        //    flag = rd["flag"] is DBNull ? flag : rd["flag"].ToString();
        //    dwt = rd["dwt"] is DBNull ? dwt : rd["dwt"].ToString();
        //    charter_type = rd["charter_type"] is DBNull ? charter_type : rd["charter_type"].ToString();
        //    size_class = rd["size_class"] is DBNull ? size_class : rd["size_class"].ToString();
        //    vessel_type = rd["vessel_type"] is DBNull ? vessel_type : rd["vessel_type"].ToString();
        //    created_date = rd["created_date"] is DBNull ? created_date : Convert.ToDateTime(rd["created_date"]);
        //    modified_date = rd["modified_date"] is DBNull ? modified_date : Convert.ToDateTime(rd["modified_date"]);
        //}
        public bool IsValidVessel()
        {
            return agr_dim_value != string.Empty && agr_rel_value != string.Empty;
        }
        public override string ToString()
        {
            return agr_description + " [" + agr_dim_value + "] [" + agr_rel_value + "]";
        }
    }
    


    //public class VesselSoftmar
    //{
    //    public string Vessel_Name;
    //    public string Vessel_Type;
    //    public string Flag;
    //    public string Year_of_build;
    //    public string Dwt;
    //    public string Vessel_Code;
    //    public string Size_Class;

    //    public VesselSoftmar() { }
    //    public VesselSoftmar(SqlDataReader rd)
    //    {
    //        Vessel_Name = rd["Vessel_Name"] is DBNull ? "" : rd["Vessel_Name"].ToString();
    //        Vessel_Type = rd["Vessel_Type"] is DBNull ? "" : rd["Vessel_Type"].ToString();
    //        Flag = rd["Flag"] is DBNull ? "" : rd["Flag"].ToString();
    //        Year_of_build = rd["Year_of_build"] is DBNull ? "" : rd["Year_of_build"].ToString();
    //        Dwt = rd["Dwt"] is DBNull ? "" : rd["Dwt"].ToString();
    //        Vessel_Code = rd["Vessel_Code"] is DBNull ? "" : rd["Vessel_Code"].ToString();
    //        Size_Class = rd["Size_Class"] is DBNull ? "" : rd["Size_Class"].ToString();
    //    }
    //}
}
